<template>
  <div id="app">
  	 <transition name="custom-classes-transition" :enter-active-class="enterClass">
  	 	 <router-view></router-view>
  	 </transition>
     <!-- loading bar -->
     <div class="loading-bar"  v-show="loadingShow">
       <img class="loading-img" src="./images/loading.gif" />
       <p class="loading-text">正在加载中...</p>
     </div>
     <div class="loading-bg"  v-show="loadingShow"></div>
  </div>
</template>

<script>
import {mapState} from 'vuex'

export default {
  name: 'app',
  watch: {
    $route (to, from) {
      document.title = to.meta.title
      if (to.path === '/preview') {
        this.enterClass = 'animated slideInRight'
      } else if (from.path === '/preview') {
        this.enterClass = 'animated slideInLeft'
      } else {
        this.enterClass = ''
      }
    },
    isLoading (val) {
      if (!val) {
        setTimeout(() => {
          this.loadingShow = false
        }, 500)
      } else {
        this.loadingShow = true
      }
    }
  },
  computed: {
    ...mapState([
      'isLoading'
    ])
  },
  data () {
    return {
      enterClass: '',
      loadingShow: false
    }
  }
}
</script>

<style>
.loading-bg{
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  background: rgba(0, 0, 0, .2);
  z-index: 998;
}

.loading-bar{
  position: fixed;
  left: 50%;
  top: 50%;
  margin-top: -80px;
  z-index: 999;
}

.loading-bar .loading-img{
  height: 102px;
  width: 130px;
}

.loading-bar .loading-text{
  text-align: center;
  color:#fff;
  font-size: 16px;
  font-weight: 500;
  margin-top: 10px;
}
</style>
